const fs = require('fs');
const path = require('path');

// 配置参数
const maxDepth = 2;  // 最大深度
const ignoreList = new Set(['.git', 'node_modules', '.idea']); // 忽略目录

function printTree(dir, prefix = '', depth = 1, isLast = true) {
    if (depth > maxDepth) return;

    try {
        const items = fs.readdirSync(dir)
            .filter(item => !ignoreList.has(item))
            .sort((a, b) => a.localeCompare(b)); // 按字母排序

        items.forEach((item, index) => {
            const fullPath = path.join(dir, item);
            const isDir = fs.statSync(fullPath).isDirectory();
            const isLastItem = index === items.length - 1;

            // 打印当前项目
            const connector = isLast ? '└─ ' : '├─ ';
            console.log(`${prefix}${connector}${item}${isDir ? '/' : ''}`);

            // 递归打印子目录
            if (isDir) {
                const newPrefix = prefix + (isLast ? '   ' : '│  ');
                printTree(fullPath, newPrefix, depth + 1, isLastItem);
            }
        });
    } catch (err) {
        console.error(`无法读取目录: ${dir}`);
    }
}

// 使用当前工作目录
const targetDir = process.cwd();
console.log(path.basename(targetDir) + '/');
printTree(targetDir, '', 1);